import {
	post,
	get,
} from '@/api/request.js'

const getCategory = async () => {
	const res = await get('/v3/index/category')
	if (!res) return
	return res
}

const getTur = async (_this) => {
	let typeInd = _this.typeInd;
	const params = {
		'ind': typeInd
	}
	const res = await get('/v3/index/GetTurjan', params)
	if (!res) return
	// console.log(res);
	const tur = res.data.data
	_this.searchObj.tur = tur
}

const getSearch = async (_this) => {
	// console.log(_this);
	_this.$emit('setLoading', true)
	let keyword = _this.keyword;
	let fenbie = _this.fenbie;
	let typeInd = _this.typeInd;
	let dolatInd = _this.dolatInd;
	let vip = _this.vip;
	let list = _this.list;
	let timeInd = _this.timeInd;
	let page = _this.page + 1;

	const turRes = await getTur(_this)

	const params = {
		tur: fenbie,
		rayon: dolatInd,
		yil: timeInd,
		title: keyword,
		vip: vip,
		kino: typeInd,
		page: page,
	}
	const res = await post('/v3/index/search', params)
	if (!res) return
	// 页码更新
	_this.page = page
	// 结束加载
	_this.$emit('setLoading', false)
	// 返回数据
	return res
}

module.exports = {
	getCategory,
	getSearch,
}